package 作业5.Microblogging;
import java.util.Date;
import java.util.HashSet;
import java.util.Scanner;

public class Test {
    //用户数据
    private static HashSet<User> USER_DATA=new HashSet<User>();
    //用户操作类
    private static UserManager objuserManager=new UserManager(USER_DATA);
    //用户验证类
    private static UserVerification userVerfi=new UserVerification();
    //输入类
    private static  Scanner scanner=new Scanner(System.in);
    //用户类
    static User objuser;
    @SuppressWarnings("resource")
    public static void main(String[] args) {
        //初始化部分
        initData();
        //接受用户输入信息
        UserInput();
        while(true){
            //注册
            if (!objuserManager.UserRegistraton(objuser)) {
                //注册失败
                System.out.println("你是否继续注册:0:不,1:是");
                if (new Scanner(System.in).nextInt()==0) {
                    break;
                }
                //接受用户输入信息
                UserInput();
                if (objuserManager.UserRegistraton(objuser)) {
                    break;
                }
            }else {
                //注册成功
                break;
            }
        }
        System.out.println("----------当前集合中用户信息----------");
        System.out.println(USER_DATA);

    }

    //初始化信息
    private static void initData() {
        // TODO Auto-generated method stub
        User user=new User("张三","zq,123",new Date().toString(),"18618121193","zhouqi@itcast.cn");
        USER_DATA.add(user);
    }

    //用户信息输入
    @SuppressWarnings("static-access")
    private static void UserInput() {
        //创建对象
        objuser=new User();
        //输入用户名
        inputUserName(scanner);
        //输入密码和确认密码
        inputPwd(scanner);
        //输入生日
        inputBirthday(scanner);
        //输入手机号
        inpitTelNumber(scanner);
        //输入邮箱
        inputEmail(scanner);
    }


    //输入用户名
    private static void inputUserName(Scanner scanner) {
        // TODO Auto-generated method stub
        System.out.print("请输入用户名:");
        objuser.setUserName(scanner.nextLine());
    }

    //输入密码和确认密码
    @SuppressWarnings("static-access")
    private static void inputPwd(Scanner scanner) {
        // TODO Auto-generated method stub
        System.out.print("请输入密码:");
        objuser.setPwd(scanner.nextLine());
        System.out.print("确认密码:");
        objuser.setRePwd(scanner.nextLine());
        while (true) {
            if (userVerfi.VerifyPwd(objuser)) {
                //密码和确认密码正确
                break;
            }
            System.out.print("请重新输入密码:");
            objuser.setPwd(scanner.nextLine());
            System.out.print("请重新输入确认密码:");
            objuser.setRePwd(scanner.nextLine());
        }
    }

    //输入出生日期
    @SuppressWarnings("static-access")
    private static void inputBirthday(Scanner scanner) {
        // TODO Auto-generated method stub
        System.out.print("出生日期:");
        while (true) {
            objuser.setBirthday(scanner.nextLine());
            if (userVerfi.VerifyBirthday(objuser)) {
                break;
            }
            System.out.print("请重新输入生日:");
        }
    }

    //输入手机号
    @SuppressWarnings("static-access")
    private static void inpitTelNumber(Scanner scanner) {
        // TODO Auto-generated method stub
        System.out.print("手机号码:");
        while (true) {
            objuser.setTelNumber(scanner.nextLine());
            if (userVerfi.VerifyTelNumber(objuser)) {
                break;
            }
            System.out.print("请重新输入手机号码:");
        }
    }


    //输入邮箱
    @SuppressWarnings("static-access")
    private static void inputEmail(Scanner scanner) {
        // TODO Auto-generated method stub
        System.out.print("邮箱:");
        while(true){
            objuser.setEmail(scanner.nextLine());
            if (userVerfi.VerifyEmail(objuser)) {
                break;
            }
            System.out.print("请重新输入邮箱:");
        }
    }
}
